
import { WeElement, define } from 'omi'

import './index.css'

define('page-my_youhui', class extends WeElement {
  config = {
    navigationBarTitleText: '兑换优惠券'
  }

  data = {
    wd_bg:"",
    yuehuan_icon:"",
    wd_pic:"",
    num:""
  }

  install() {
    this.data.wd_bg = require('../images/wd_bg.png'),
      this.data.wd_pic = require('../images/wd_pic.png'),
      this.data.yuehuan_icon = require('../images/yuehuan_icon.png'),
    this.update()
  }
  open=()=>{
    if(/[0-9]/.test(this.data.num) && this.data.num.length==5){
      console.log("right");
      // wx.navigateTo({
      //   url: '..',
      // })
    } else if (this.data.num==""){
      console.log("兑换码不能为空");
      wx.showToast({
        title: '兑换码不能为空',
        icon:'none',
        mask:true
      })
    }else{
      wx.showModal({
        title: '小提示',
        content: '该兑换码不存在',
        showCancel:false
      })
    }
  }
  num=(e)=>{
    this.data.num=e.detail.value;
    this.update;
  }
  render() {
    return (
      <view class="container">
        <image class="wd_bg" src={wd_bg}></image>
        <view class="content">
          <image class="wd_pic" src={wd_pic}></image>
          <view class="change_box">
            <view class="title">请输入您的兑换码</view>
            <form class="box">
              <input class="num" type="number" maxlength="5" bindblur={this.num}></input>
              <button class="submit" bindtap={this.open}>立即兑换</button>
              <image class="yuehuan_icon" src={yuehuan_icon}></image>
            </form>
          </view>
        </view>
        
      </view>
    )
  }
})